package com.cqeec.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.cqeec.domain.Student;
import com.cqeec.domain.Teacher;
import com.cqeec.utils.JDBCUtils;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import java.awt.Font;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.awt.event.ActionEvent;
/**
 *  教师主界面
 * @author 邓学强
 *
 */

public class TeacherInterface extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private static JLabel label;
	private static StudentInterface frame;
	private static Teacher teacher;
	private static Connection conn;
	/**
	 * Launch the application.
	 */
	public static void main(Teacher teacher) {
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TeacherInterface.teacher = teacher;
					TeacherInterface.conn = JDBCUtils.getConnection();
					TeacherInterface frame = new TeacherInterface();
					frame.setVisible(true);String path = "src/img/zsxx_bg.jpg";
					// 背景图片
					ImageIcon background = new ImageIcon(path);
					// 把背景图片显示在一个标签里面
					label = new JLabel(background);

					// 把标签的大小位置设置为图片刚好填充整个面板
					label.setBounds(0, 0, 1044, 648);
					// 把内容窗格转化为JPanel，否则不能用方法setOpaque()来使内容窗格透明
					JPanel imagePanel = (JPanel) frame.getContentPane();
					imagePanel.setOpaque(false);
					// 把背景图片添加到分层窗格的最底层作为背景
					frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
					frame.setResizable(false);// 设置窗体不可拖动
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TeacherInterface() {
		setTitle("教师主界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100,1044, 648);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu menu = new JMenu("学生考勤");
		menu.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 20));
		menuBar.add(menu);
		
		JMenuItem menuItem = new JMenuItem("课堂点名");
		/**
		 * 课堂点名 单击事件
		 */
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				contentPane.setVisible(false);
				Denominate den=  new Denominate(conn,teacher);
				den.setVisible(true);
				label.add(den);
				
				
			}
		});
		
		
		menuItem.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 17));
		menu.add(menuItem);
		
		JMenuItem menuItem_1 = new JMenuItem("请假查看");
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				contentPane.setVisible(false);
				 SeeLeave seeLeave=new SeeLeave();
				 seeLeave.setVisible(true);
				label.add(seeLeave);
			}
		});
		menuItem_1.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 17));
		menu.add(menuItem_1);
		
		JMenu menu_1 = new JMenu("教师信息");
		menu_1.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 20));
		menuBar.add(menu_1);
		/**
		 * 修改密码事件
		 */
		JMenuItem menuItem_2 = new JMenuItem("修改密码");
		menuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new ModifyPassword(teacher);
			}
		});
		menuItem_2.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 17));
		menu_1.add(menuItem_2);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
	}

}
